package com.leetcode.algorithm.y22.m06;

/**
 * 744. 寻找比目标字母大的最小字母
 * 
 * https://leetcode.cn/problems/find-smallest-letter-greater-than-target/
 * 
 * @author jie.deng
 *
 */
class Question0744Solution01 {

	public char nextGreatestLetter(char[] letters, char target) {
		int left = 0;
		int right = letters.length;
		while (left < right) {
			int mid = left + ((right - left) >> 1);
			if (letters[mid] - target <= 0) {
				left = mid + 1;
			} else {
				right = mid;
			}
		}
		return right == letters.length ? letters[0] : letters[right];
	}

}